<html>
<head>
<script src="../../resources/js-test.js"></script>
<script>
description('Tests that unicode-range descriptor is used to selectively download fonts that are used in document.');

window.jsTestIsAsync = true;

var latin1Loaded = false;
var cyrillicLoaded = false;
var arabicLoaded = false;
var iconLoaded = false;

function runTests() {
    document.fonts.addEventListener('loadingdone', onloadingdone);
}

function onloadingdone(e) {
    for (var i = 0; i < e.fontfaces.length; i++) {
        var range = e.fontfaces[i].unicodeRange;
        if (range == 'U+0-FF')
            latin1Loaded = true;
        if (range == 'U+400-4FF')
            cyrillicLoaded = true;
        if (range == 'U+600-6FF')
            arabicLoaded = true;
        if (range == 'U+E000')
            iconLoaded = true;
    }

    shouldBeFalse('latin1Loaded');
    shouldBeTrue('cyrillicLoaded');
    shouldBeFalse('arabicLoaded');
    shouldBeFalse('iconLoaded');
    finishJSTest();
}

if (document.fonts)
    runTests();
else {
    testFailed('document.fonts does not exist');
    finishJSTest();
}
</script>
<style>
@font-face {
    font-family: TestFont;
    src: url('../../resources/Ahem.ttf');
    unicode-range: U+00-0FF;  /* Latin-1 */
}
@font-face {
    font-family: TestFont;
    src: url('../../resources/Ahem.otf');
    unicode-range: U+0400-04FF;  /* Cyrillic */
}
@font-face {
    font-family: TestFont;
    src: url('../../resources/Ahem.woff');
    unicode-range: U+0600-06FF;  /* Arabic */
}
#test {
    font-family: TestFont;
}

@font-face {
    font-family: SingleCharacterOverride;
    src: url('../../resources/Ahem.woff');
    unicode-range: U+E000;
}
#test2 {
    font-family: SingleCharacterOverride;
}
</style>
</head>
<body>
  <p id="test">&#x41F;&#x440;&#x43E;&#x432;&#x435;&#x440;&#x43A;&#x430;</p>
  <p id="test2">hello</p>
</body>
</html>
